package com.nowcoder.community.dao;

import com.nowcoder.community.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 花木凋零成兰
 * @date 2024/3/15 15:59
 */
@Mapper
public interface CommentMapper {

    /**
     * 分页查询
     * @param entityType
     * @param entityId
     * @param offset
     * @param limit
     * @return
     */
    List<Comment> selectCommentsByEntity(int entityType, int entityId, int offset, int limit);

    /**
     * 获取回复帖子 的数目
     * @param entityType
     * @param entityId
     * @return
     */
    @Select("select count(id) from comment where status = 0 and entity_id = #{entityId} and entity_type = #{entityType}")
    int selectCountByEntity(int entityType, int entityId);

    /**
     * 添加评论
     * @param comment
     * @return
     */
    int insertComment(Comment comment);

    /**
     * 根据id查询 评论
     * @param id
     * @return
     */
    @Select("select * from comment where id = #{id}")
    Comment findCommentById(int id);

}
